package edu.sjsu.cs.files;

/**
 * COPYRIGHT(C) 2007. Cay Horstmann. All Rights Reserved.
   A bank account has a balance that can be changed by
   deposits and withdrawals.
   @author Natasha Khuri
   @version 1.01 2007-01-04
*/
public class BankAccount
{
   /**
      Constructs a bank account with a zero balance.
   */
   public BankAccount()
   {
      balance = 0;
   }

   /**
      Constructs a bank account with a given balance.
      @param initialBalance the initial balance
      @throws IllegalArgumentException if amount is negative or zero
   */
   public BankAccount(double initialBalance)
   {
      balance = initialBalance;
   }

   /**
      Deposits money into the bank account.
      (Precondition amount > 0)
      @param amount the amount to deposit

   */
   public void deposit(double amount)
   {
      if (amount <= 0)
      {
         throw new IllegalArgumentException("Negative Deposit.");
      }
      double newBalance = balance + amount;
      balance = newBalance;
   }

   /**
      Withdraws money from the bank account.
      (Precondition amount <= balance and amount > 0)
      @param amount the amount to withdraw
      @throws IllegalArgumentException if amount is negative
      or amount is greater than balance

   */
   public void withdraw(double amount)
   {
      if(amount>balance || amount<=0)
      {
         throw new IllegalArgumentException("Not enough money.");
      }
      double newBalance = balance - amount;
      balance = newBalance;
   }

   /**
      Gets the current balance of the bank account.
      @return the current balance
   */
   public double getBalance()
   {
      return balance;
   }

   private double balance;
}
